package com.jhc.drone.communication.service.impl;


import com.jhc.drone.communication.datagram.command.Command;
import com.jhc.drone.communication.enums.WsReqEnum;
import com.jhc.drone.communication.network.cache.DroneCache;
import com.jhc.drone.communication.service.CmdService;
import com.jhc.drone.communication.vo.CmdVo;
import com.jhc.drone.communication.vo.CommandVo;
import com.jhc.drone.communication.ws.WsEndpoint;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author lcp
 * @date 2025年03月2025/3/6 15:36
 * @describe
 */
@Service
@RequiredArgsConstructor
public class CmdServiceImpl implements CmdService {

    @Override
    public void processCmd(CmdVo vo) {
        CommandVo commandVo = new CommandVo();
        commandVo.setSysId(DroneCache.getSysId(vo.getSn()));
        switch (vo.getDrone()) {
            case ARM:
                commandVo.setWsReqEnum(WsReqEnum.ARM);
                break;
            case TAKE_OFF:
                commandVo.setWsReqEnum(WsReqEnum.TAKE_OFF);
                break;
            case RETURN:
                commandVo.setWsReqEnum(WsReqEnum.RETURN);
                break;
            case LAND:
                commandVo.setWsReqEnum(WsReqEnum.LAND);
            case MANUAL_MODE:
                commandVo.setWsReqEnum(WsReqEnum.SET_MODE);
                commandVo.setParam2(1);
                break;
            case MISSION_MODE:
                commandVo.setWsReqEnum(WsReqEnum.SET_MODE);
                commandVo.setParam2(15);
                break;
            case POINT_MODE:
                commandVo.setWsReqEnum(WsReqEnum.SET_MODE);
                commandVo.setParam2(5);
                break;
            default:
                break;
        }
        byte[] bytes = Command.buildCommand(commandVo);
        WsEndpoint.messageProcessor.send(bytes, vo.getSn());
    }


}
